const http = require('http')
const server = http.createServer()
server.on('request',(req,res)=>{
    // 1、获取请求的url地址
    const url = req.url
    //2、设置默认内容为404 not find
    let content = '<h1>404 not find</h1>'

    //3、判断用户请求是否为/或/index.html首页

    //4、判断用户请求是否为/about.html关于页面
    if(url==='/'||url ==='/index.html'){
        content='<h1>首页</h1>'
    }else if(url==='/about.html'){
        content='<h1>关于页面</h1>'
    }
    // 5、设置Content-Type响应头防止乱码
    res.setHeader('Content-Type','text/HTMLAllCollection;charset=utf-8')
    //6、使用res.end()方法把内容返回给客户端
    res.end(content)

})
server.listen(8080,()=>{
    console.log('server runing at http://127.0.0.1');
})